package com.rd.teacher.jichao.day03;

public class StringBuilderTest {

    public static void main(String[] args) {
        String str = "zhang";
        StringBuilder stringBuilder = new StringBuilder(str);
        StringBuffer stringBuffer = new StringBuffer(str);

        // 转换为String
        stringBuilder.toString();
        stringBuffer.toString();

        // 互相转化
        StringBuilder s1 = new StringBuilder(stringBuffer.toString());
        StringBuffer s2 = new StringBuffer(stringBuilder.toString());

        String str10 = ",";
        String str11 = "zhang" + "san" + str10 + "li" + "si" + str10 + "wang" + "wu";
        System.out.println(str11);

        StringBuilder sstr = new StringBuilder();
        // 初始容量 16
        System.out.println(sstr.capacity());

        StringBuilder sstr1 = new StringBuilder(10);
        System.out.println(sstr1.capacity());

        StringBuilder sstr2 = new StringBuilder("中软睿达");
        System.out.println(sstr2.capacity());

        sstr.append("zhang");
        sstr.append("san");
        sstr.append(str10);
        sstr.append("li");
        sstr.append("si");
        sstr.append(str10);
        sstr.append("wang");
        sstr.append("wu");
        // 反转整个字符串
//        sstr = sstr.reverse();
        // 删除和插入
        // 删除是左闭右开的区间 [9,14)  插入是在指定位置前插入字符串
//        sstr = sstr.delete(9,14);
//        sstr.insert(9,"zhaoliu,");

//        sstr.toString();

        // 容量
        System.out.println(sstr.capacity());

        sstr.setCharAt(0,'s');
        System.out.println(sstr);

        sstr.deleteCharAt(0);
        System.out.println(sstr);

    }
}
